local jLootz = jLootz
local lib = jLootz:GetModule("Frame")

local confirm

local function ActivateChildren(enable, slot)
	for _, frame in pairs(lib.buttons) do
		if type(frame) == "table" then
			if enable then
				frame.button:Enable()
				if frame.slot == slot then
					frame.button:UnlockHighlight()
				end
			else
				frame.button:Disable()
				if frame.slot == slot then
					frame.button:LockHighlight()
				end
			end
		end
	end
end

function lib:ShowConfirm(frame, slot)
	if confirm == nil then
		confirm = jLootz:GetConfirmModule() or false
	end
	if not confirm then
		local _, item, _, quality = GetLootSlotInfo(slot)
		local dialog = StaticPopup_Show("LOOT_BIND", ITEM_QUALITY_COLORS[quality].hex..item.."|r")
		if dialog then
			dialog.data = slot
		end
	else
		confirm:SetArguments("Confirm", ConfirmLootSlot, ActivateChildren, slot)
		confirm:Show(frame)
	end
end

function lib:HideConfirm()
	if not confirm then
		StaticPopup_Hide("LOOT_BIND")
	else
		confirm:Hide()
	end
end
